package com.controller.ipself;

import org.lucksyc.utilindependent.resultview.core.data.ViewData;
import org.lucksyc.utilindependent.resultview.seed.deal.ViewBuilder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.upper.service.ipself.IpSelfInterface;

/**
 * @author wsq
 */
@Controller
@RequestMapping("/ipself")
public class IpSelfController {
	private static final Logger log = LoggerFactory.getLogger(IpSelfController.class);
	
	@Autowired
	ViewBuilder viewBuilder;
	
	@Autowired
	IpSelfInterface ipSelfInterface;
	
	@ResponseBody
	@GetMapping("/getMyselfList")
	public ViewData getMyselfList() {
		log.debug("getMyselfList.");
		try {
			return ipSelfInterface.getMyselfList();
		} catch (Exception e) {
//			e.printStackTrace();
			log.info("getMyselfList:"+e.getMessage());
		}
		return viewBuilder.failed();
	}
	
	@ResponseBody
	@GetMapping("/addMyself")
	public ViewData addMyself(String ip) {
		log.debug("addMyself.");
		try {
			return ipSelfInterface.addMyself(ip);
		} catch (Exception e) {
//			e.printStackTrace();
			log.info("addMyself:"+e.getMessage());
		}
		return viewBuilder.failed();
	}
	
	@ResponseBody
	@GetMapping("/delMyself")
	public ViewData delMyself(String id) {
		log.debug("delMyself.");
		try {
			return ipSelfInterface.delMyself(id);
		} catch (Exception e) {
//			e.printStackTrace();
			log.info("delMyself:"+e.getMessage());
		}
		return viewBuilder.failed();
	}
}
